﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            登录名称：<input id="userName" name="UserName" type="text" />
                        </li>
                        <li>
                            操作方法：<input id="executeUrl" name="ExecuteUrl" type="text" />
                        </li>
                        <li>
                            操作状态：<span id="logStatus" name="LogStatus"></span>
                        </li>
                        <li class="select-time">
                            <label>操作时间： </label>
                            <input id="startTime" name="StartTime" type="text" class="time-input" placeholder="开始时间" />
                            <span>-</span>
                            <input id="endTime" name="EndTime" type="text" class="time-input" placeholder="结束时间" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            @*<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>*@
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            @*<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                    <i class="fa fa-download"></i> 导出
                </a>*@
            <a id="btnDelete" class="btn btn-danger" onclick="removeAllForm()"><i class="fa fa-trash"></i> 清空</a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable"></table>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {

        $("#logStatus").ysComboBox({ data: ys.getJson(@Html.Raw(typeof(OperateStatusEnum).EnumToDictionaryString())) });
        //初始时间
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            var startDate = laydate.render({
                elem: '#startTime',
                theme: 'molv',
                trigger: 'click',
            });
            var endTime = laydate.render({
                elem: '#endTime',
                theme: 'molv',
                trigger: 'click',
            });
        });
        var options = {
            id: "gridTable",
            url: "/SystemManage/LogApi/GetPageListJson",
            createUrl: "",
            updateUrl: "",
            removeUrl: "/SystemManage/LogApi/DeleteFormJson",
            sortName: "BaseCreateTime",
            sortOrder: "desc",
            modalName: "数据",
           columns: [
                { checkbox: true, visible: true },
                { field: 'id', title: 'Id', visible: false },
                { field: 'userName', title: '登录名称' },
                { field: 'departmentName', title: '部门名称' },
                { field: 'executeUrl', title: 'Url' },
                { field: 'executeTime', title: '耗时（ms）' },
                {
                    field: 'logStatus', title: '执行状态', align: 'center',
                    formatter: function (value, row, index) {
                        if (value == "@OperateStatusEnum.Success.ParseToInt()") {
                            return '<span class="badge badge-primary">' + "@OperateStatusEnum.Success.GetDescription()" + '</span>';
                        } else {
                            return '<span class="badge badge-warning">' + "@OperateStatusEnum.Fail.GetDescription()" + '</span>';
                        }
                    }
                },
                {
                    field: 'baseCreateTime', title: '请求时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="#" onclick="showDetailForm(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a>');
                        return actions.join('');
                    }
                }
            ],
            onClickRow: function (row, element) {
                element[0].firstElementChild.firstElementChild.click();
            }
        };
        $.table.init(options);
    });

    function removeAllForm() {
        ys.confirm("确认要清空表吗？", function () {
            ys.ajax({
                url: '/SystemManage/LogApi/RemoveAllFormJson")',
                type: "post",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        searchGrid();
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        });
    }

    function showDetailForm(id) {
        ys.openDialog({
            title: "操作日志详细",
            content: '/SystemManage/LogApi/LogOperateDetail?id=' + id
        });
    }
</script>

